<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
    <script>
        s = "   -42"

        var myAtoi = function(str) {
            var num = parseInt(str)
            if (num>=Math.pow(2,31)-1){
                return Math.pow(2,31)-1
            }
            if (num<=Math.pow(-2,31)){
                return Math.pow(-2,31)
            }
            return isNaN(parseInt(str))?0:parseInt(str)
        };
        console.log(myAtoi(s));


    </script>
</body>
</html>